<template>
	<view>
		<view>
			<view class="uni-padding-wrap uni-common-mt">
				<view class="uni-title uni-common-mt">
					Vertical Scroll
				</view>
				<view>
					<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scrolltoupper="upper"
						@scrolltolower="lower" @scroll="scroll">
						<view id="demo1" class="scroll-view-item uni-bg-red">A</view>
						<view id="demo2" class="scroll-view-item uni-bg-red">B</view>
					</scroll-view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		apis,
		routes
	} from '@/common/paths.js'
	export default {
		data() {
			return {
				user_token: uni.getStorageSync('user_token'),
				scrollTop: 0,
				old: {
					scrollTop: 0
				},
				routes:routes

			}
		},
		methods: {
			upper: function(e) {
				console.log('upper', e)
			},
			lower: function(e) {
				console.log('lower ',e)
			},
			scroll: function(e) {
				console.log('scroll', e)
				this.old.scrollTop = e.detail.scrollTop
			},
			goTop: function(e) {
				//解决view层不同步的问题
				this.scrollTop = this.old.scrollTop
				this.$nextTick(function() {
					this.scrollTop = 0
				});
				//提示窗
				uni.showToast({
					icon: "none",
					title: "纵向滚动 scrollTop 值已被修改为 0"
				})

			},
			loadProjWorkbench(project_id){
				uni.request({
					url: this.backendServer + apis['do_workbench'],
					method: 'get',
					data: {
						'user_id': this.user_token,
						'project_id': project_id
					},
					success: (res) => {
						uni.hideLoading()
						console.log('success res ', res)
						if (res.data.status) {
							console.log('request ok')
							this.project_list = res.data.project_list
							console.log("project_list: " + JSON.stringify(this.project_list));
						} else {
							uni.showToast({
								title: "获取失败，"+res.data.msg,
								icon: 'fail'
							})
							uni.switchTab({
								url: routes['mine']
							})
						}
					},
					fail: (res) => {
						uni.hideLoading()
						console.log('fail res ', res)
						uni.showToast({
							title: "获取失败，请检查网络联接",
							icon: 'fail'
						})
						uni.switchTab({
							url: routes['index']
						})
						// this.project_list = []
					}
				})
			}
		},
		onLoad() {
			console.log('onLoad load project ids')
			// loadProjectInfos(){
			// 	uni.request({
			// 		// url:
			// 	})
			// }
		}
	}
</script>

<style>
	.scroll-Y {
		height: 300rpx;
	}

	.scroll-view_H {
		white-space: nowrap;
		width: 100%;
	}

	.scroll-view-item {
		height: 300rpx;
		line-height: 300rpx;
		text-align: center;
		font-size: 36rpx;
	}

	.scroll-view-item_H {
		display: inline-block;
		width: 100%;
		height: 300rpx;
		line-height: 300rpx;
		text-align: center;
		font-size: 36rpx;
	}
</style>